//
//  AppDelegate+TXIM.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/9/5.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "AppDelegate+TXIM.h"
#import "TICManager.h"
#import "TICConfig.h"

@interface AppDelegate () <TIMConnListener,TIMUserStatusListener,TIMMessageListener,TICStatusListener>

@end


@implementation AppDelegate (TXIM)
//初始化腾讯sdk
- (void)initTXIMSdk {
    [[TICManager sharedInstance] addStatusListener:self];
//     初始化TICSDK
    [[TICManager sharedInstance] init:1400305387 callback:^(TICModule module, int code, NSString *desc) {
        if(code == 0){
            
        }
    }];
    TIMManager * manager = [TIMManager sharedInstance];
    TIMSdkConfig *config = [[TIMSdkConfig alloc] init];
    config.sdkAppId = 1400305387;//这个id是写死的。不存在转换（....）
    config.connListener = self;
    config.disableLogPrint = YES;
    [manager initSdk:config];

    [[TIMManager sharedInstance] addMessageListener:self];
    
}
/**
 *  踢下线通知
 */
- (void)onForceOffline {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"账号被踢" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [(UINavigationController *)self.window.rootViewController popToRootViewControllerAnimated:YES];
    }];
    [alert addAction:action];
    UIViewController *currentVC = ((UINavigationController *)self.window.rootViewController).topViewController;
    [currentVC presentViewController:alert animated:YES completion:nil];
}

#pragma mark - TIMMessageListener
/**
 *  新消息回调通知
 *
 *  @param msgs 新消息列表，TIMMessage 类型数组
 */
- (void)onNewMessage:(NSArray*) msgs {
     [[NSNotificationCenter defaultCenter] postNotificationName:TUIKitNotification_TIMMessageListener object:msgs];
}
//接受群组消息id
- (void)onTICRecvGroupCustomMessage:(NSData *)data groupId:(NSString *)groupId fromUserId:(NSString *)fromUserId {
    
}
@end
